package month4.day25;

import com.sun.xml.internal.ws.api.model.MEP;

import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;

public class Market {
    Set<Member> set=new HashSet<Member>();
    Map<String, Integer>shangpin=new HashMap<>();
    public Market() {
        shangpin.put("餐巾纸", 100);
        shangpin.put("剃须刀", 500);
        shangpin.put("汽车", 50000);
    }
    //开卡
    public boolean kaika(String name,String code){
        int jifen=100;
        Member member=new Member(name,code,jifen);
        return set.add(member);
    }
    //检验
    public Member jianyan(String name,String code){
        for(Member m:set){
            if(name.equals(m.getName())&&code.equals(m.getCode()))
                return m;
        }
        return null;
    }
    //修改密码
    public void xiugai(String name,String code,String newcode){
        Member m=jianyan(name,code);
        if(m==null)
            System.out.println("没有该用户");
        else {
             m.setCode(newcode);
            System.out.println("修改成功");
        }
    }
    //剩余积分
    public void shengyui(String name,String code){
        Member m=jianyan(name,code);
        if(m==null)
            System.out.println("没有该用户");
        else
            System.out.println("剩余积分："+m.getMinute());
    }
    //兑换
    public boolean duihuan(String name,String code,String Shangpin){
        Member m=jianyan(name,code);
        if(m==null) {
            System.out.println("没有该用户");
            return false;
        }
        if (this.shangpin.containsKey(Shangpin)&&m.getMinute()>= this.shangpin.get(shangpin)) {
            m.setMinute(m.getMinute() - this.shangpin.get(shangpin));
            System.out.println("兑换成功");
            return true;
        }
        System.out.println("商品不存在");
        return false;

    }
    //累积积分
    public boolean leiji(String name,String code,double money){
        Member m=jianyan(name,code);
        if(m==null) {
            System.out.println("没有该用户");
            return false;
        }
        m.setMinute(m.getMinute()+0.1*money);
        System.out.println("加分成功");
        return true;
    }
    //删除会员
    public boolean shanchu(String name,String code){
        Member m=jianyan(name,code);
        if(m==null)
            System.out.println("没有该用户");
        else{
            set.remove(m);
            System.out.println("删除成功");
            return true;
        }
        return false;
    }


}
